/*$('a.n_answer').live('click',function (){
if ($(this).attr('toggle') == 'open') {
$(this).attr('toggle', 'close');
$(this).removeClass('n_answer_opened')
$(this).parents('.comment_item').next('.discuss').hide()
refresh_subcomments(cid);
} else {
$(this).attr('toggle', 'open');
$(this).addClass('n_answer_opened')
$(this).parents('.comment_item').next('.discuss').show();
}
return false;
});*/

$.ajaxSetup({
        beforeSend : function (xhr, settings) {
            function getCookie(name) {
                var cookieValue = null;
                if (document.cookie && document.cookie != '') {
                    var cookies = document.cookie.split(';');
                    for (var i = 0; i < cookies.length; i++) {
                        var cookie = jQuery.trim(cookies[i]);
                        // Does this cookie string begin with the name we want?
                        if (cookie.substring(0, name.length + 1) == (name + '=')) {
                            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                            break;
                        }
                    }
                }
                return cookieValue;
            }
            if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
                // Only send the token to relative URLs i.e. locally.
                try {
                    xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
                } catch (err) {
                    //alert(err.description);
                }
            }
        }
    });

var show_answers = function (selector, cid) {
    if ($(selector).attr('toggle') == 'open') {
        $(selector).attr('toggle', 'close');
        $(selector).removeClass('n_answer_opened')
        $('#one_articlecomment_' + cid + ' .discuss').hide()
    } else {
        $(selector).attr('toggle', 'open');
        $(selector).addClass('n_answer_opened')
        $('#one_articlecomment_' + cid + ' .discuss').show();
        refresh_subcomments(cid);
    }
    return false;
}

$('a.answer').live('click', function () {
        if ($(this).attr('toggle') == 'open') {
            $(this).attr('toggle', 'close');
            commentId = $(this).attr('commentid');
            reset_comment(commentId);
        } else {
            $(this).attr('toggle', 'open')
            commentId = $(this).attr('commentid');
            subcomment(commentId, user_object);
        }
        return false;
    });

/**************************************
 *  Block comments until sort is done *
 *************************************/
$('#comments_ordering').live('change', function () {
        //$('.images_loader').show();
        var commH = $('#article_addon .comments').height();
        var commW = $('#article_addon .comments').width();
        $('#article_addon .comments').append('<div class="comm_block"></div>');
        $('#article_addon .comments .comm_block').width(commW);
        $('#article_addon .comments .comm_block').height(commH);
        $('#article_addon .comments .comm_block').append('<div class="preload"></div>');
        $.ajax({
                dataType : 'JSON',
                url : _refresh_comment_url + '&order=' + $('#comments_ordering').val(),
                success : function (html) {
                    $('#article_addon .comments .comm_block').remove();
                    $('#article_' + _article_id + '_comments_only').html(html);
                    //$('.images_loader').hide();
                }
            });
        //$('#article_pagination_' + _article_id).load(_pagination_url + '?page=1&type=' + _comment_type);
        return false;
    });

/**************************************
 *  Block comments until sort is done *
 *************************************/
comments_ordering_fn = function (comm_order, page, callback) {
    if (!page) {
        page = '&page=' + 1;
    } else {
        page = '&page=' + page;
    }
    //$('.images_loader').show();
    if (!comm_order) {
        comm_order = $('#comments_ordering').val() + '&save=yes'
    } else {
        comm_order += '&save=no';
    }
    try {
        var perpage = '&perpage=' + _article_comments_perpage;
    } catch (e) {
        var perpage = '';
    }
    $.ajax({
            dataType : 'JSON',
            url : _refresh_comment_url + '&order=' + comm_order + perpage + page,
            success : function (html) {
                $('#article_' + _article_id + '_comments_only').html(html);
                //$('.images_loader').hide();
                if (callback) {
                        callback();
                }
            }
        });
    //$('#article_pagination_' + _article_id).load(_pagination_url + '?page=1&type=' + _comment_type);
    return false;
}

$('#show_ordered_comments').live('click', function () {
        $(this).toggleClass('aw_toggle');
        /*if ($('a.n_answer').attr('toggle') == 'open') {
        $('a.n_answer').attr('toggle', 'close');
        $('a.n_answer').removeClass('n_answer_opened')
        $('a.n_answer').parents('.comment_item').next('.discuss').hide()
        } else {
        $('a.n_answer').attr('toggle', 'open');
        $('a.n_answer').addClass('n_answer_opened')
        $('a.n_answer').parents('.comment_item').next('.discuss').show();
        }*/
        $('li.answer a').click();
        return false;
    });

subcomment = function (cid, user) {
    var html = '<span class="gfx">&nbsp;</span><form method="post" action="#">' +
                    '<ul>' +
                        '<li class="user_data">' +
                            user.avatar +
                            '<a class="user" href="' + user.url + '" title="' + user.name + '">' +
                                user.name +
                            '</a><br>';
    if (user.badge) {
        html += '<a class="badge" href="#" title="' + user.badge + '">' + user.badge + '</a>, ';
    }
    if (user.karma) {
        html += 'Bodovi: <strong>' + user.karma + '</strong>';
    }
    html += '</li>' +
                        '<li class="textarea">' +
                            '<textarea name="user_text_sub" cols="65" rows="10" id="id_user_text_sub"></textarea>' +
                            '<a href="/pravila-komentiranja/" target="_blank">Pravila Komentiranja</a>' +
                            '<input type="submit" class="button" name="subcomment_submit" id="subcomment_submit" value="Komentiraj" onclick="submit_comment(' + cid + ');return false;" />' +
                            '<a class="quit" href="#" title="' + subcomment_reset_button + '" onclick="reset_comment(' + cid + ');return false;">' + subcomment_reset_button + '</a>' +
                        '</li>' +
                    '</ul>' +
                '</form>';
    $('.discuss_box').hide(0, function () {
            $('.discuss_box').html('');
            $('#discuss_box_' + cid).html(html);
            $('#discuss_box_' + cid).show();
            $('#id_user_text_sub').focus();
        });
    comments_selected_cid = cid;
}

/***********************************
 *  Block like until ajax finishes *
 **********************************/
like_enabled = true;
like = function (comment_id, un, sub, cookie) {
    if (like_enabled) {
        
        $('ul.#rating_' + comment_id).addClass('like_progress');
        like_enabled = false;
        
        if (!cookie) {
            cookie = false;
        }
        
        if (!sub) {
            sub = ''
        }
        $.ajax({
                dataType : 'JSON',
                type : "POST",
                data : {
                    'comment_id' : comment_id,
                    'like' : un,
                    'type' : _comment_type
                },
                url : refresh_article_comment_meta_options,
                error : function (XMLHttpRequest, error, exception) {
                    $('ul #rating_' + comment_id).removeClass('like_progress');
                    like_enabled = true;
                    if (XMLHttpRequest.responseText != 'forbidden') {
                        flashmessage('DoÅ¡lo je do pogreÅ¡ke. Probajte malo kasnije. Hvala na razumijevanju.');
                    }
                    
                },
                success : function () {
                    $('#rating_' + comment_id).load('/comments/article_' + sub + 'comments_meta_options/' + comment_id + '/?type=' + _comment_type, function () {
                            $('ul #rating_' + comment_id).removeClass('like_progress');
                        });
                    if (cookie == true) {
                        createCookie(_comment_type + '_' + comment_id, true, 10);
                    }
                    like_enabled = true;
                }
            });
    }
}

var spamit_sending = false;
spamit = function (comment_id) {
    if (!spamit_sending) {
        spamit_sending = true;
        $.ajax({
                dataType : 'JSON',
                type : 'POST',
                data : {
                    'comment_id' : comment_id
                },
                url : '/comments/spamit',
                error : function (req, error, exception) {
                    spamit_sending = false;
                    flashmessage(req.responseText);
                },
                success : function () {
                    spamit_sending = false;
                    flashmessage('Poruka je prijavljena. Zahvaljujemo na VaÅ¡em doprinosu.');
                }
            })
    };
};

/**************************************
 *  Show hide inittext on flur, focus *
 *************************************/
/*$('#id_user_text').live('focus', function () {
        if ($(this).val() == 'Klikni ovdje ukoliko Å¾eliÅ¡ komentirati') {
            $(this).val('');
            $(this).removeAttr('class');
            $(this).parent().parent().children('li').children('input.button').show();
        }
    })

$('#id_user_text').live('blur', function () {
        if ($(this).val() == '') {
            $(this).val('Klikni ovdje ukoliko Å¾eliÅ¡ komentirati');
            $(this).attr('class', 'click_comm_box');
            $(this).parent().parent().children('li').children('input.button').hide();
        }
    })*/

/*
$(document).ready(function(){
$('ul.comment_item li p').each(function(key,comment){
html = comment.innerHTML
if (html.length > 300) {
new_html = html.substring(0,300) +
'<span class="three_dots">...</span>' +
' <span class="show_all_button">prikaÅ¾i sve</span>' +
'<span class="hidden_text" style="display:none;">' + html.substring(300,html.length) + '</span>'
comment.innerHTML = new_html
}
});
});
 */

$('span.shortened_comment span.show_all_button a').live('click', function () {
        //alert($(this).parent().parent().attr('class'));
        $(this).parent().parent().attr('class', 'complete_text');
    });

submit_comment = function (cid, last_comment) {
    if (cid) {
        var postdata = {
            'text' : $('#id_user_text_sub').val(),
            'aid' : _article_id,
            'cid' : cid,
            'type' : _comment_type
        };
        container = 'id_user_text_sub';
    } else {
        var postdata = {
            'text' : $('#id_user_text').val(),
            'aid' : _article_id,
            'type' : _comment_type
        };
        container = 'id_user_text';
    }
    if ($('#' + container).val() == '') {
        flashmessage(_type_something_msg);
        return false;
    }
    
    comment_length = $('#' + container).val().length
        if (comment_length > _comments_length) {
            flashmessage('Komentar je predug (' + comment_length + ' znakova). Skratite komentar na ' + _comments_length + ' znakova.');
            return false;
        }
        
        $('#comment_submit').attr('disabled', 'disabled');
    $('#comment_submit').css('comm_disabled');
    $('#' + container).attr('readonly', 'readonly');
    $('#' + container).addClass('comm_disabled');
    
    $.ajax({
            dataType : 'JSON',
            type : "POST",
            data : postdata,
            url : _submit_comment_url,
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                if (XMLHttpRequest.responseText.substring(2, 13) == 'uskrsnojaje') {
                    eval('var error_obj=' + XMLHttpRequest.responseText);
                    msg = error_obj['uskrsnojaje'];
                    $('#comment_submit').removeAttr('disabled');
                    $('#comment_submit').removeClass('comm_disabled');
                    $('#' + container).removeAttr('readonly');
                    $('#' + container).removeClass('comm_disabled');
                    $('#id_user_text').val('Klikni ovdje ukoliko Å¾eliÅ¡ komentirati');
                    $('#id_user_text').attr('class', 'click_comm_box');
                    $('#comment_submit').hide();
                } else {
                    if (XMLHttpRequest.responseText == 'FAIL') {
                        msg = 'DoÅ¡lo je do pogreÅ¡ke. Probajte malo kasnije. Hvala na razumijevanju.';
                    } else {
                        msg = XMLHttpRequest.responseText;
                    }
                    
                    $('#comment_submit').removeAttr('disabled');
                    $('#comment_submit').removeClass('comm_disabled');
                    $('#' + container).removeAttr('readonly');
                    $('#' + container).removeClass('comm_disabled');
                }
                flashmessage(msg);
            },
            success : function () {
                
                if (cid) {
                    refresh_comment(cid);
                } else {
                    if (last_comment) {
                        $('#last_comment_container').load(_last_comment_url);
                    } else {
                        //refresh_comments();
                        comments_ordering_fn('id',9999999999999, function(){scroll_to_comment_box();});
                        //$('#id_user_text').val('');
                        $('#' + container).removeAttr('readonly');
                        $('#' + container).removeClass('comm_disabled');
                        
                        $('#id_user_text').val('Klikni ovdje ukoliko Å¾eliÅ¡ komentirati');
                        $('#id_user_text').attr('class', 'click_comm_box');
                        
                        $('#comment_submit').hide();
                    };
                };
                $('#comment_submit').removeAttr('disabled');
                $('#comment_submit').removeClass('comm_disabled');
            }
        });
}

reset_comment = function (cid) {
    $('#discuss_box_' + cid).hide();
    $('#user_text_sub').val('');
}

refresh_comments = function (order, page) {
    page = (!page) ? '' : 'page=' + page;
    order = (!order) ? '&' + page : '&order=' + order + page;
    $('#article_' + _article_id + '_comments_only').load(_refresh_comment_url + order + perpage, function () {
            $('.images_loader').hide();
        });
}

refresh_comment = function (cid) {
    $('#article_comment_' + cid).load('/comments/commrefresh/' + cid + '/?type=' + _comment_type, function () {
            $('#article_subcomments_' + cid).show();
            refresh_subcomments(cid);
        });
}

refresh_subcomments = function (cid) {
    $('#article_subcomments_' + cid).load('/comments/subrefresh/' + cid + '/?type=' + _comment_type, function () {
            reset_comment(cid);
        });
}

seeall = function (article_id) {
    $('#article_' + article_id + '_comments').load('/comments/refresh/' + article_id + '/?all=1', function () {
            $('#seeallcomments_' + article_id).hide();
        });
}

admin_edit_text = function (comment_id) {
    postdata = {
        'comment_id' : comment_id,
        'text' : $('#textbox_admin_edit').val()
    }
    $.ajax({
            dataType : 'JSON',
            type : "POST",
            data : postdata,
            url : _submit_admin_edit_comment_url,
            onerror : null,
            success : function () {
                popupclose();
                $('#article__comments').load(_submit_admin_edit_comment_succ_url);
            }
        });
}

var scroll_to = function(container, shift){
    var offset = $(container).offset();
    $("html:not(:animated),body:not(:animated)").animate({ scrollTop: offset.top+shift}, 500 );
}
var scroll_to_comments = function(){
    scroll_to('.scroll_to_comments',-70);
}
var scroll_to_comment_box = function(){
    scroll_to('.scroll_to_comment_box',-300);
}

pagination = function (page) {
    var commH = $('#article_addon .comments').height();
    var commW = $('#article_addon .comments').width();
    $('#article_addon .comments').append('<div class="comm_block"></div>');
    $('#article_addon .comments .comm_block').width(commW);
    $('#article_addon .comments .comm_block').height(commH);
    $('#article_addon .comments .comm_block').append('<div class="preload"></div>');
    try {
        perpage = '&perpage=' + _article_comments_perpage
    } catch (e) {
        perpage = '';
    }
    $.ajax({
            dataType : 'JSON',
            url : _refresh_comment_url + '&page=' + page + '&order=' + $('#comments_ordering').val() + perpage,
            success : function (html) {
                $('#article_addon .comments .comm_block').remove();
                $('#article_' + _article_id + '_comments_only').html(html);
            }
        });
    scroll_to_comments();
    //$('#article_upper_pagination_' + _article_id).load(_pagination_url + '?page=' + page + '&type=' + _comment_type);
    //$('#article_pagination_' + _article_id).load(_pagination_url + '?page=' + page + '&type=' + _comment_type);
}

lastcommentbox = function () {
    $('#last_comment_box').show();
    $('#last_comment_box textarea').focus();
    //$.scrollTo('#last_comment_box textarea');
}

var delete_comment = function (comment_id) {
    var yes_delete = confirm("Å½elite li obrisati svoj komentar?");

    if (yes_delete) {
        $.ajax({
            dataType : 'JSON',
            url : '/comments/delete_article_comment/' + comment_id + '/?type=' + _comment_type,
            success : function (html) {
                $('#one_articlecomment_' + comment_id).fadeOut(500);
            }
        });
    };
}

send_feedback = function () {
    postdata = {
        'ime' : $('#fdb_block #ime').val(),
        'prezime' : $('#fdb_block #prezime').val(),
        'email' : $('#fdb_block #email').val(),
        'poruka' : $('#fdb_block #poruka').val()
    }
    
    $.ajax({
            dataType : 'JSON',
            type : "POST",
            data : postdata,
            url : "/feedback/",
            error : function (XMLHttpRequest, error, exception) {
                
                $('#fdb_block #ime input').attr('style', 'background-color: #FFFCF2;');
                $('#fdb_block #prezime ').attr('style', 'background-color: #FFFCF2;');
                $('#fdb_block #email').attr('style', 'background-color: #FFFCF2;');
                $('#fdb_block #poruka').attr('style', 'background-color: #FFFCF2;');
                eval("var obj=" + XMLHttpRequest.responseText);
                for (var key in obj) {
                    if (obj[key]) {
                        $('#fdb_block #' + key).attr('style', 'background-color: #ff0000;');
                    }
                }
            },
            success : function () {
                $('#owerlay_block').hide();
            }
        });
}

$('span.div_link').live('click', function () {
        var href = $(this).attr('url')
            window.open(href, '_blank').blur();
    })

/*$(document).ready(function() {

$('.comments div div ul.comment_item  li.meta li.answer:first').addClass('fila');
$('.comments div div ul.comment_item  li.meta li.answer:last').addClass('fila');
});*/

function slideshowFn(images_name, class_name) {
    
    var slide_speed = 3000;
    var fade_speed = 1500;
    
    if ($("a." + images_name).length > 0) {
        
        var slideArr = new Array();
        
        $("a." + images_name).each(function () {
                
                var slide_images = $(this);
                slideArr.push(slide_images.attr("href"));
            })
        
        if (slideArr.length < 2) {
            return
        }
        
        var slide_img = $("a." + images_name).parent().find("a." + class_name + " > img");
        var slide_bck = $("a." + images_name).parent().find("a." + class_name);
        
        function slideoneFn() {
            slide_bck.attr("style", "background-image:url(" + slideArr[1] + ");");
            
            slide_img.delay(slide_speed).fadeOut(fade_speed, function () {
                    
                    slideArr.push(slideArr.shift());
                    slide_img.attr("src", slideArr[0]);
                    slide_img.fadeIn(1000, function () {
                            slideoneFn();
                        });
                })
        }
        
        slideoneFn();
    }
}

$('form[ajax="jquery"] input[type="submit"]').live('click', function () {
        var form = $(this).parents('form');
        var container = form.parent();
        
        if (!form.attr('action')) {
            return;
        }
        
        if (!form.attr('method')) {
            var method = 'POST';
        } else {
            var method = form.attr('method');
        }
        
        var name_iterrations = new Array();
        var data = {};
        var set_name = function (obj) {
            if (obj.attr('name')) {
                var name = obj.attr('name');
            } else if (obj.attr('id')) {
                var name = obj.attr('id');
            } else {
                if (!name_iterrations[obj.attr('type')]) {
                    name_iterrations[obj.attr('type')] = 0;
                } else {
                    name_iterrations[obj.attr('type')] += 1;
                }
                var name = obj.attr('type') + '_' + name_iterrations[obj.attr('type')];
            }
            return name;
        }
        form.find('input').each(function (index) {
                var name = set_name($(this));
                data[name] = $(this).val();
            });
        form.find('textarea').each(function (index) {
                var name = set_name($(this));
                data[name] = $(this).val();
            });
        
        form.find('input').attr('disabled', 'disabled');
        form.find('textarea').attr('disabled', 'disabled');
        form.find('input').attr('style', 'background-color:#eee !important;border:#ccc !important;');
        form.find('textarea').attr('style', 'background-color:#eee !important;border:#ccc !important;');
        
        var ajax_form_req = $.ajax({
                    type : method,
                    url : form.attr('action'),
                    data : data,
                    success : function (data) {
                        //clearTimeout(abort_if_expired);
                        container.html(data);
                        $.ajax({
                                dataType : 'JSON',
                                url : '/box/flashmessage/',
                                success : function (msg) {
                                    flashmessage(msg);
                                }
                            });
                    },
                    error : function () {
                        form.find('input').removeAttr('disabled');
                        form.find('textarea').removeAttr('disabled');
                        form.find('input').attr('style', '');
                        form.find('textarea').attr('style', '');
                        $.ajax({
                                dataType : 'JSON',
                                url : '/box/flashmessage/',
                                success : function (msg) {
                                    flashmessage(msg);
                                }
                            });
                    }
                });
        /*var ajax_req_expired = function(){
        ajax_form_req.abort();
        form.find('input').removeAttr('disabled');
        form.find('textarea').removeAttr('disabled');
        flashmessage('DoÅ¡lo je do greÅ¡ke kod slanja forme. Molimo probajte malo kasnije. Hvala na razumijevanju.');
        }
        var abort_if_expired = setTimeout('ajax_req_expired()', 30000);*/
    });

$(document).ready(function () {
        
        /*$("tooltip_cloud").mouseover(function() {
        $(this).css("display","none")
        })*/
        /*$('.wrap_all').not('.wrap_all .container_12').bind('click', function(){
        document.location = "/specijal/oscar";
        })*/
        
        $('.NjuContainerIteml').mouseout(function () {
                var thesrc = $(this).find("img").attr('src');
                var name = thesrc.substring(0, thesrc.lastIndexOf('.jpg'));
                $(this).find("img").attr("src", name + "-zatvoren.jpg");
                $(this).find("div").find("span").removeClass('Label2').addClass('Label1');
            });
        $('.NjuContainerIteml').mouseover(function () {
                var thesrc = $(this).find("img").attr('src');
                var name = thesrc.substring(0, thesrc.lastIndexOf('-zatvoren.jpg'));
                $(this).find("img").attr("src", name + ".jpg");
                $(this).find("div").find("span").removeClass('Label1').addClass('Label2');
            });
        
        $('.NjuContainerItem2').mouseout(function () {
                var thesrc = $(this).find("img").attr('src');
                var name = thesrc.substring(0, thesrc.lastIndexOf('.jpg'));
                $(this).find("img").attr("src", name + "-zatvoren.jpg");
            });
        $('.NjuContainerItem2').mouseover(function () {
                var thesrc = $(this).find("img").attr('src');
                var name = thesrc.substring(0, thesrc.lastIndexOf('-zatvoren.jpg'));
                $(this).find("img").attr("src", name + ".jpg");
            });
        
        /************************
         * Atricle side content *
         ***********************/
        if ($("#article_content").height()) {
            var articleH = $("#article_content").height();
            var rightItems = 100;
            var bannerHeight = 250;
            
            if ($('#banner_frame').height() > 300) {
                var bannerHeight = 600;
            };
            
            var rightItemH = new Array(["banner_frame", bannerHeight, "inline"], //bannerType],
                    ["joke_of_the_day", 200, "inline"],
                    ["more_in_section5", 400, "inline"],
                    ["more_in_section3", 250, "inline"],
                    ["more_in_section1", 100, "inline"],
                    ["multimedia", 310, "inline"], //_article_side_content_multimedia],
                    ["frontpage_stories5", 680, "inline"],
                    ["frontpage_stories3", 515, "inline"],
                    ["frontpage_stories1", 350, "inline"],
                    ["mostcom_recomend", 300, "inline"], //_article_side_content_mostcom_recomend],
                    ["weather_side", 290, "inline"], //_article_side_content_weather_side],
                    ["tv_side_article", 285, "inline"]//_article_side_content_tv_side_article]
                );
            
            $.each(rightItemH, function (key, val) {
                    $("#" + val[0]).css('display', 'none');
                });
            
            var skip = false;
            $.each(rightItemH, function (key, val) {
                    
                    if (skip == false) {
                        
                        $("#" + val[0]).css('display', 'none');
                        
                        rightItems += val[1];
                        
                        if (rightItems < articleH) {
                            
                            if (val[2] != "inline") {
                                $.ajax({
                                        type : "GET",
                                        url : val[2],
                                        dataType : "html",
                                        success : function (html) {
                                            document.getElementById(val[0]).innerHTML = html;
                                            $('.tabs').tabs();
                                            $('.master_tabs').tabs();
                                            if (val[0] == "weather_side") {
                                                jQuery('.select_style').select_skin();
                                            }
                                        }
                                    });
                            }
                            
                            $("#" + val[0]).css('visibility', 'visible');
                            $("#" + val[0]).css('display', 'block');
                            
                            if (val[0].indexOf("5") != -1) {
                                skip = 3;
                            }
                            if (val[0].indexOf("3") != -1) {
                                skip = 2;
                            }
                            
                        } else {
                            rightItems -= val[1];
                        }
                    }
                    
                    if (skip != false) {
                        skip -= 1;
                        if (skip == 0) {
                            skip = false
                        }
                    }
                });
        }
        
        /*     if($("div.banner_sec_top").height()){
        if($("div.banner_sec_top #leatherboard div").height()){
        //$("div.banner_sec_top").css('display', 'none');
        }else{$("div.banner_sec_top").hide(350);
        }
        }
        
        if($("div.banner_sec_top_sexy").height()){
        if($("div.banner_sec_top_sexy #leatherboard div").height()){
        //$("div.banner_sec_top").css('display', 'none');
        }else{$("div.banner_sec_top_sexy").hide(350);
        }
        }*/
        
        function placeThumb(autoplay) {
            var obj = $('#tv_accordian ul.nav li a.current');
            var obj2 = $('#tv_accordian ul.nav li.ui-tabs-selected').removeClass('ui-tabs-selected');
            $('#tv_accordian ul.nav li a.current').parent().parent().addClass('ui-tabs-selected');
            $('#tv_accordian ul.nav li a.current').removeClass('current');
            var src = obj.attr('rev');
            var img = obj.attr('rel2');
            
            if (src) {
                
                $("#player2").remove();
                $("#flash").append('<div href="' + src + '" id="player2" style="display:block;width:318px;height:191px;cursor:pointer""></div>');
                if (!autoplay) {
                    $("#player2").append('<img src="' + img + '" alt="TV widget" />');
                }
                flowplayer("player2", {
                        src : "/www/swf/flowplayer-3.2.5-1.swf",
                        wmode : "transparent",
                        key : "#@25ce75176365d6ebc6e"
                    }, {
                        play : {
                            replayLabel : 'pogledaj ponovo'
                        }
                    });
            }
        };
        
        if ($("#tv_widget").length > 0) {
            
            var tv_widgetURL;
            var imageurl = "";
            var section = $('#tv_accordian ul.nav').attr('id').substring(3);
            if (section == "home") {
                imageurl = "/www/images/tmp/news.jpg";
                section = ""
            } else if (section == "") {
                imageurl = "/www/images/tmp/news.jpg";
                section = ""
            } else {
                imageurl = "/www/images/tmp/" + section + ".jpg";
            }
            
            if (section != "") {
                section = "-" + section
            }
            
            $.getJSON('/www/tv/clip' + section + '.js',
                function (data) {
                    
                    for (i = 0; i < data.length; i++) {
                        
                        var channel = data[i].category.slug;
                        var title = data[i].name;
                        var url = data[i].media_item.full_path;
                        
                        if (i == 0) {
                            var klasa = 'current';
                        } else {
                            klasa = "";
                        }
                        
                        var html = '<li><h4><a class="truncate ' + klasa + '"style="white-space:nowrap; cursor:pointer" id="video_' + i + '" rev="' + url + '" rel="' + url + '" title="' + title + '" rel2="' + imageurl + '">' + title + '</a></h4></li>';
                        $('#tv_accordian ul.nav').append($(html));
                    }
                    
                    $('#tv_accordian ul.nav li a').click(function () {
                            var obj = $(this);
                            
                            if (obj.hasClass('current')) {
                                
                                return false;
                                
                            } else {
                                
                                obj.addClass('current');
                                placeThumb(true);
                            }
                            
                            return false;
                            
                        });
                    
                    $('#tv_accordian ul.nav li:first-child a').addClass('current');
                    $('.truncate').truncateWord();
                    placeThumb(false);
                })
        }
        
        if ($("#mini_games_block").length > 0) {
            
            $.getJSON('http://24sata.igre.hr/json.php?ref=24sata&callback=?',
                function (games) {
                    
                    var html = '<li style="float: left;">';
                    
                    var game = games.length;
                    if (game > 12) {
                        game = 12
                    }
                    
                    for (i = 0; i < game; i++) {
                        
                        var title = games[i].name;
                        var description = games[i].description;
                        var thumbnail = games[i].thumbnail;
                        var game_url = games[i].game_url;
                        
                        html += '    <div class="box"><img width="154" height="103" alt="Games" title="Games" src="' + thumbnail + '">';
                        html += '        <h3><a target="_self" href="' + game_url + '" title="' + title + '"><span>' + title + '</span></a></h3>';
                        html += '        <p>' + description + '</p>';
                        html += '    </div>';
                        
                        if (i == 5) {
                            
                            html += '</li><li style="float: left;">';
                        }
                    }
                    
                    html += '</li>';
                    $('#mini_games_block .games_slider ul').append($(html));
                    
                    // EasySlider
                    $('#mini_games_block .games_slider').each(function (i) {
                            i = i + 1;
                            $(this).addClass('g_slide_multi_' + i);
                            $('.g_slide_multi_' + i).easySlider({
                                    prevId : 'prevBtnG' + i,
                                    nextId : 'nextBtnG' + i
                                });
                        });
                    
                    $('.games_slider .box').hover(
                        function () {
                            $(this).addClass('box_hover');
                        },
                        function () {
                            $(this).removeClass('box_hover');
                        });
                    
                })
        }
        
        $('#hit_beta .box_1-8 p.lead').truncateLines();
        $('#hit_beta .box_1-2 p.lead').truncateLines();
        //$('#hit_beta .box_1-8 h3').truncateLines();
        $('#hit_alpha .box_1-8 p.lead').truncateLines();
        
        // article galerija
        
        function checkDescPlaceholder() {
            var txt = $('#desc_placeholder').text();
            
            if (txt != '') {
                $('#desc_placeholder').removeClass('displaynone');
            } else {
                $('#desc_placeholder').addClass('displaynone');
            }
        }
        
        function placeimg() {
            if ($('#slider_gall').length > 0) {
                var obj = $('#slider_gall ul.slider li a.current');
                
                var src = obj.attr('href');
                var title = obj.attr('title');
                var meta = obj.attr('rev');
                var author = meta.substring(0, meta.indexOf("_dim"));
                var id = obj.attr('id');
                var width = meta.substr(meta.indexOf("_dim") + 4, 3);
                var height = meta.substr(meta.indexOf("_dim") + 8, 3);
                
                var clickedHref = $("#" + id + "fb").attr('href');
                $('#fancyboxShow').attr('href', clickedHref )
                
                if (src) {
                    
                    $('#embed_placeholder').hide();
                    
                    if (src.indexOf("24TV_Live.smil") != -1) {
                        
                        $('#flash').removeClass('displaynone');
                        $('#place').addClass('displaynone');
                        $('#desc_placeholder').hide();
                        $('#author_placeholder').show();
                        $('#author_placeholder').text(author);
                        
                        $("#player2").remove();
                        $("object").remove();
                        $('#flash').append('<a id="player2" style="display:block;width:504px;height:318px;"> </a>');
                        flowplayer("player2", {
                                src : "/www/swf/flowplayer-3.2.5-1.swf",
                                wmode : "transparent",
                                key : "#@25ce75176365d6ebc6e"
                            }, {
                                play : {
                                    replayLabel : 'pogledaj ponovo'
                                },
                                plugins : {
                                    // our CDN uses SMIL playlists ..
                                    smil : {
                                        url : '/www/swf/flowplayer.smil-3.2.2.swf'
                                    },
                                    // .. and RTMP streaming
                                    rtmp : {
                                        url : '/www/swf/flowplayer.rtmp-3.2.3.swf'
                                    }
                                },
                                clip : {
                                    url : src,
                                    provider : 'rtmp',
                                    live : true
                                }
                            });
                        
                    } else if (src.indexOf(".smil") != -1) {
                        
                        $('#flash').removeClass('displaynone');
                        $('#place').addClass('displaynone');
                        $('#desc_placeholder').hide();
                        $('#author_placeholder').show();
                        $('#author_placeholder').text(author);
                        
                        $("#player2").remove();
                        $("object").remove();
                        $('#flash').append('<a id="player2" style="display:block;width:504px;height:318px;"> </a>');
                        flowplayer("player2", {
                                src : "/www/swf/flowplayer-3.2.5-1.swf",
                                wmode : "transparent",
                                key : "#@25ce75176365d6ebc6e"
                            }, {
                                play : {
                                    replayLabel : 'pogledaj ponovo'
                                },
                                plugins : {
                                    // our CDN uses SMIL playlists ..
                                    smil : {
                                        url : '/www/swf/flowplayer.smil-3.2.2.swf'
                                    },
                                    // .. and RTMP streaming
                                    rtmp : {
                                        url : '/www/swf/flowplayer.rtmp-3.2.3.swf'
                                    },
                                    kockica : {
                                        url : '/www/swf/kockica.swf',
                                        top : 20,
                                        right : 20
                                    }
                                },
                                clip : {
                                    url : src,
                                    provider : 'rtmp',
                                    live : true
                                }
                            });
                        
                    } else if (src.indexOf(".f4v") != -1 || src.indexOf(".flv") != -1) {
                        
                        $('#flash').removeClass('displaynone');
                        $('#place').addClass('displaynone');
                        $('#desc_placeholder').hide();
                        $('#author_placeholder').show();
                        $('#author_placeholder').text(author);
                        $('#embed_placeholder').show();
                        $('#embed_placeholder span').text(src)
                        
                        $("#player2").remove();
                        $("object").remove();
                        $('#flash').append('<a href="' + src + '" id="player2" class="embed_true" style="display:block;width:504px;height:318px;"> </a>');
                        flowplayer("player2", {
                                src : "/www/swf/flowplayer-3.2.5-1.swf",
                                wmode : "transparent",
                                key : "#@25ce75176365d6ebc6e"
                            }, {
                                play : {
                                    replayLabel : 'pogledaj ponovo'
                                }
                        });
                        
                    } else if (src.indexOf("youtube.com") != -1) {
                        
                        src = src.replace(new RegExp("watch\\?v=", "i"), 'v/') + "&fs=1";
                            
                        $('#flash').removeClass('displaynone');
                        $('#place').addClass('displaynone');
                        $('#desc_placeholder').hide();
                        $('#author_placeholder').show();
                        $('#author_placeholder').text(author);
                        
                        $("object").remove();
                        $("#player2").remove();
                        
                        if($('.videoholder').length > 0){
                          $('#flash').append('<object width="100%" height="100%" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="100%" height="100%" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                        }else{
                          $('#flash').append('<object width="504" height="318" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="504" height="318" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                        }
                        
                    } else if (src.indexOf(".jpg") != -1 || src.indexOf(".jpeg") != -1) {
                        $('#flash').addClass('displaynone');
                        $('#place').removeClass('displaynone');
                        $('#desc_placeholder').show();
                        $('#author_placeholder').show();
                        $('#place').hide();
                        
                        $('#place').load(function () {
                                $(this).fadeIn(500);
                                $(this).attr('title', title);
                                $(this).attr('rel', id);
                                $(this).attr('width', width);
                                $(this).attr('height', height);
                            }).error(function () {
                                // notify the user that the image could not be loaded
                            }).attr('src', src);
                        
                        //$('#place').attr('src', src);
                        $('#desc_placeholder').text(title);
                        $('#author_placeholder').text(author);
                    } else {
                        
                        src = "http://www.youtube.com/v/" + src + "&fs=1";;
                        
                        $('#flash').removeClass('displaynone');
                        $('#place').addClass('displaynone');
                        $('#desc_placeholder').hide();
                        
                        $("object").remove();
                        $("#player2").remove();
                        $('#flash').append('<object width="504" height="318" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="504" height="318" allowfullscreen="true" wmode="window" type="application/x-shockwave-flash" src="' + src + '"></object>');
                        
                    }
                    
                    //obj.removeAttr('href');
                    obj.children('img').animate({
                            opacity : 0.4
                        });
                    checkDescPlaceholder();
                };
            }
        }
        
        /* galerija slider big buttnons */
        if ($('#slider_gall .slider a').size() <= 6) {
            $("#nextBtnGall a").hide();
        }
        placeimg();
        
        $('#slider_gall ul.slider li a').click(function () {
                var obj = $(this);
                
                var clickedImg = $(this).attr("id")
                var clickedHref = $("#" + clickedImg + "fb").attr('href');
                $('#fancyboxShow').attr('href', clickedHref )
                
                if (obj.hasClass('current')) {
                    //obj.removeClass('current');
                    return false;
                } else {
                    $('#slider_gall').find('a.current img').animate({
                            opacity : 1
                        });
                    $('#slider_gall').find('a.current').removeClass('current');
                    obj.addClass('current');
                    placeimg();
                    prevInLink();
                    nextInLink();
                }
                return false;
                
            });
        
        //provjera dali je galerija na pocetku ili kraju te micem ili stavljam linkove na sliku
        function prevInLink() {
            if ($('#slider_gall ul li:first').children().is('a:first-child.current')) {
                $('#slider_gall a.prevBtnLarge').css('display', 'none');
            } else {
                $('#slider_gall a.prevBtnLarge').css('display', 'block');
            }
        };
        prevInLink();
        
        function nextInLink() {
            if ($('#slider_gall ul li:last').children().is('a:last-child.current')) {
                $('#slider_gall a.nextBtnLarge').css('display', 'none');
            } else {
                $('#slider_gall a.nextBtnLarge').css('display', 'block');
            }
            
        };
        nextInLink();
        
        //linkovi na slici, surfanje po galeriji sa fajdanjem liste
        $('#slider_gall a.prevBtnLarge').click(function () {
                
                var current = $('#slider_gall ul.slider a.current');
                
                if (current.prev().is('a') || current.parent().prev().children().is('a')) {
                    $('#slider_gall ul.slider').find('a.current img').animate({
                            opacity : 1
                        });
                    if (current.is('a:first-child')) {
                        current.parent().prev().children('a:last-child').addClass('current');
                        $("a", "#prevBtnGall").focus();
                        $("a", "#prevBtnGall").click();
                    } else {
                        current.prev().addClass('current');
                    }
                    current.eq(0).removeClass('current');
                    $('#slider_gall a.nextBtnLarge').css('display', 'block');
                    prevInLink();
                }
                placeimg();
            });
        
        $('#slider_gall a.nextBtnLarge').click(function () {
                
                var current = $('#slider_gall ul.slider a.current');
                
                if (current.next().is('a') || current.parent().next().children().is('a')) {
                    $('#slider_gall ul.slider').find('a.current img').animate({
                            opacity : 1
                        });
                    if (current.is('a:last-child')) {
                        current.parent().next().children('a:first-child').addClass('current');
                        $("a", "#nextBtnGall").focus();
                        $("a", "#nextBtnGall").click();
                    } else {
                        current.next().addClass('current');
                    }
                    current.eq(0).removeClass('current');
                    $('#slider_gall a.prevBtnLarge').css('display', 'block');
                    nextInLink();
                }
                placeimg();
                
            });
        
        $('#fancyboxShow').click(function () {
            var imgID = $("#place").attr('rel');
            $("#" + imgID + "fb").focus();
            $("#" + imgID + "fb").click();
        });
        
            
        // samostalni img, CDN, youtube
        var obj = $('a#player3');
        var src = obj.attr('href');
        
        
        if (src != null) {
            
            $('#embed_placeholder').show();
            
            if($('#gallery_page').length){
                 videoWidth =$('#gallery_page .inner').width();
                 videoHeight =$('#gallery_page .inner').height();
                
                if( videoWidth > 900 )   { videoWidth = 900 }
                if( videoHeight > 600 )  { videoHeight = 600 }
            }
            
            /*if($('#anketa_block').length){
                 videoWidth = 564;
                 videoHeight = 375;
            }*/
            
            
            videoWidth = '100%';
            videoHeight = '100%';
            
            if (src.indexOf("24TV_Live.smil") != -1) {
                
                $('a.#player3').append('<div href="' + src + '" id="player2" style="display:block;width:504px;height:338px"> </div>');
                
                flowplayer("player2", {
                        src : "/www/swf/flowplayer-3.2.5-1.swf",
                        wmode : "transparent",
                        key : "#@25ce75176365d6ebc6e"
                    }, 
                    {
                        play : {
                            replayLabel : 'pogledaj ponovo'
                        },
                        plugins : {
                            smil : {
                                url : '/www/swf/flowplayer.smil-3.2.2.swf'
                            },
                            rtmp : {
                                url : '/www/swf/flowplayer.rtmp-3.2.3.swf'
                            }
                        },
                        clip : {
                            url : src,
                            provider : 'rtmp',
                            live : true,
                            onBegin : function (clip) {
                                this.unmute()
                            }
                        }
                    });
                
            } else if (src.indexOf(".smil") != -1) {
                
                $('a.#player3').append('<div href="' + src + '" id="player2" style="display:block;width:504px;height:338px"> </div>');
                
                flowplayer("player2", {
                        src : "/www/swf/flowplayer-3.2.5-1.swf",
                        wmode : "transparent",
                        key : "#@25ce75176365d6ebc6e"
                    }, {
                        play : {
                            replayLabel : 'pogledaj ponovo'
                        },
                        plugins : {
                            smil : {
                                url : '/www/swf/flowplayer.smil-3.2.2.swf'
                            },
                            rtmp : {
                                url : '/www/swf/flowplayer.rtmp-3.2.3.swf'
                            },
                            kockica : {
                                url : '/www/swf/kockica.swf',
                                top : 20,
                                right : 20
                            }
                        },
                        clip : {
                            url : src,
                            provider : 'rtmp',
                            live : true,
                            onBegin : function (clip) {
                                this.unmute()
                            }
                        }
                    });
                
            } else if (src.indexOf(".f4v") != -1 || src.indexOf(".flv") != -1) {
                
                $('a.#player3 #embed_placeholder').show();
                if($('.videoholder').length > 0 || $('#anketa_block').length > 0 ){
                    
                    $('a.#player3').append('<div href="' + src + '" id="player2" class="embed_true" style="background:#333;margin:0 auto; display:block;width:'+ videoWidth +';height:'+ videoHeight +'"> </div>');
                }else{
                    
                    $('a.#player3').append('<div href="' + src + '" id="player2" class="embed_true" style="display:block;width:504px;height:338px"> </div>');
                }
                
                flowplayer("player2", {
                        src : "/www/swf/flowplayer-3.2.5-1.swf",
                        wmode : "transparent",
                        key : "#@25ce75176365d6ebc6e"
                    }, {
                        play : {
                            replayLabel : 'pogledaj ponovo'
                    }, clip: {
                       'scale' : 'fit'
                    }
                    });
                
            } else if (src.indexOf("youtube.com") != -1) {                
                
                src = src.replace(new RegExp("watch\\?v=", "i"), 'v/') + "&fs=1";
                    
                    if($('.videoholder').length > 0  || $('#anketa_block').length > 0 ){
                      $('a.#player3').append('<object width="'+ videoWidth +'" height="'+ videoHeight +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="'+ videoWidth +'" height="'+ videoHeight +'" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                    }else{
                      $('a.#player3').append('<object width="504" height="318" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="504" height="318" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                    }
                
                
            } else {
                
                src = "http://www.youtube.com/v/" + src + "&fs=1";
                src = src.replace(new RegExp("watch\\?v=", "i"), 'v/')
                    
                    if($('.videoholder').length > 0  || $('#anketa_block').length > 0 ){
                      $('a.#player3').append('<object width="'+ videoWidth +'" height="'+ videoHeight +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="'+ videoWidth +'" height="'+ videoHeight +'" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                    }else{
                      $('a.#player3').append('<object width="504" height="318" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="' + src + '" name="movie"><param value="transparent" name="wmode"><param value="true" name="allowfullscreen"><embed width="504" height="318" allowfullscreen="true" wmode="transparent" type="application/x-shockwave-flash" src="' + src + '"></object>');
                    }
            }
        obj.removeAttr('href');
        }
        
        
        if ($('#slider_gall').length > 0) {
            $("a.fancybox").fancybox({
                    'titlePosition' : 'over',
                    'centerOnScroll' : 'true'
                });
        }
        
        $("a.youtube").click(function () {
                $.fancybox({
                        'padding' : 0,
                        'autoScale' : false,
                        'transitionIn' : 'none',
                        'transitionOut' : 'none',
                        'title' : this.title,
                        'width' : 680,
                        'height' : 495,
                        'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                        'type' : 'swf',
                        'swf' : {
                            'wmode' : 'transparent',
                            'allowfullscreen' : 'true'
                        }
                    });
            });
        
        if ('#mini_multimedia'.length > 0) {
            $('#mini_multimedia a.FancyShow').click(function () {
                    var fb_album = $(this).attr('id');
                    $('#mini_multimedia #' + fb_album + 'fb').trigger('click');
                });
        }
        if ('#medium_multimedia'.length > 0) {
            $('#medium_multimedia a.FancyShow').click(function () {
                    var fb_album = $(this).attr('id');
                    $('#medium_multimedia #' + fb_album + 'fb').trigger('click');
                });
        }
        
        // redni broj na galerije
        var fb_i = 0;
        var fb_lnth = $('#slider_gall .fancybox').length;
        $('#slider_gall .fancybox').each(function () {
                fb_i++;
                var fb_ttl = $('#slider_gall .fancybox:nth-child(' + fb_i + ')').attr('title');
                $('#slider_gall .fancybox:nth-child(' + fb_i + ')').attr('title', '(' + fb_i + '/' + fb_lnth + ') ' + fb_ttl);
            });
        
        //$("a[href^='http']").not("a[href*='24sata.hr']").attr('target','_blank');
        $("#mini_games_block .box a.[href^='http']").attr('target', '_self');
        
        if ($(".special h2.subtitle").length > 0) {
            
            var h2w = 870 - $(".special h2").width();
            $("p.specijal").attr("style", "width:" + h2w + "px !important;");
            
        };
        
        /* focus FancyPlayer */
        function focus_fancy(p_movie) {
            var flash = null;
            
            if (navigator.appName.indexOf("Microsoft") != -1) {
                flash = window[p_movie];
            } else {
                var embeds = document.body.getElementsByTagName('embed');
                flash = embeds[0];
                var cnt;
                for (var i = 0; i < embeds.length; i++) {
                    if (embeds.item(i).name.indexOf('fancyPlayer') > 0) {
                        flash = embeds[i];
                    }
                }
            }
            if ($('.vus_holder').length > 0) {
                if (flash) {
                    flash.focus()
                };
            }
        }
        
        focus_fancy("fancyPlayer");
        
        $("a[href^='http']").not("a[href*='24sata.hr']").not("#halfpage a'").not("#kocka a'").not("#leaderboard a'").not(".box_1-8 a").not(".box_1-2 a").each(function (i) {
                if ($(this).parents('#slider_gall').length == 0) {
                    var hrefs = $(this).attr("href").split("/");
                    $(this).attr("target", "_blank");
                    $(this).attr("onClick", "recordOutboundLink(this, 'Vanjski link', '" + hrefs[2] + "' );");
                    
                    // article_content
                }
            });
        
        // drop down select
        $('.com_controls a.comsel').toggle(
            function () {
                $(this).next('.comlist').css({
                        'display' : 'block'
                    })
                $(this).addClass('s_hover');
            },
            function () {
                $(this).next('.comlist').css({
                        'display' : 'none'
                    })
                $(this).removeClass('s_hover');
            });
        
        $('.com_controls a.comsel').click(function (e) {
                e.stopPropagation();
            });
        
        $(document).click(function () {
                var obj = $('a.comsel')
                    if (obj.hasClass('s_hover')) {
                        obj.next('.comlist').css({
                                'display' : 'none'
                            })
                        obj.removeClass('s_hover');
                    }
            });
        
        $('.comlist span').not('.liveorder').click(function () {
                var hot = $(this).attr('title');
                var set = $(this).parents('.comlist').prev('a.comsel');
                set.html(hot).attr('value', hot);
                $(this).parents('.comlist').prev('.comsel').trigger('click');
                
                var order = $(this).attr('order');
                
                comments_ordering_fn(order);
                $('#comments_ordering').val(order);
                
                return false;
            });
        
        $('.comlist span.liveorder').click(function () {
                var hot = $(this).attr('title');
                var set = $(this).parents('.comlist').prev('a.comsel');
                set.html(hot).attr('value', hot);
                $(this).parents('.comlist').prev('.comsel').trigger('click');
                
                live_order = $(this).attr('order');
                get_events();
                
                return false;
            });
        
        $('.comlist span').hover(
            function () {
                $(this).addClass('hover');
            },
            function () {
                $(this).removeClass('hover');
            });
        
        var url = document.location.href.split('#');
        try {
            url = url[1];
        } catch (e) {
            url = null;
        }
        if (url == 'fb_login') {
            login_with_facebook(document.referrer);
        } else if (url == 'login') {
            do_popup({
                    url : _login_url
                });
        } else if (url == 'reg') {
            do_popup({
                    url : _registration_url
                });
        }
        
        // to article submeni
        var empty_subsections = {
            'djevojka-dana' : true,
            'sexy-fotke' : true,
            'sexy-video' : true
        };
        
        function goDownNsa() {
            var current_li = $(this); //.parent('a').parent('li');
            var this_subsection = $(current_li);
            var subsection_a = this_subsection.children('a:first');
            
            if (subsection_a.hasClass('subarticles')) {
                var subsection_slug = subsection_a.attr('rel');
                var nav_to_article = $('.nav_toarticle', this_subsection);
                var already_loaded = nav_to_article.length > 0;
                
                subsection_a.addClass('ar_hover');
                
                if (already_loaded) {
                    nav_to_article.css('display', 'block');
                } else {
                    if (!empty_subsections[subsection_slug]) {
                        subsection_a.append($("<img width='16' height='11' style='float:right;margin-top:11px;margin-right:46px;' src='/www/images/ajax-loader.gif'/>"));
                        
                        $.ajax({
                                url : '/subsection-articles-html/' + subsection_slug,
                                success : function (data) {
                                    var html_data = $(data);
                                    
                                    if (subsection_a.hasClass('ar_hover')) {
                                        html_data.css('display', 'block');
                                    }
                                    
                                    this_subsection.append(html_data);
                                    subsection_a.children('img').remove();
                                },
                                error : function (jqXHR, textStatus, errorThrown) {
                                    empty_subsections[subsection_slug] = true;
                                    subsection_a.children('img').remove();
                                }
                            });
                    }
                }
                
                $('.nav_to_article', this_subsection)
                
            }
        }
        function goUpNsa() {
            current_li = $(this); //.parent('a').parent('li');
            var this_subsection = $(current_li);
            var subsection_a = this_subsection.children('a:first');
            var nav_to_article = $('.nav_toarticle', this_subsection);
            nav_to_article.css('display', 'none');
            subsection_a.removeClass('ar_hover');
        }
        
        $('ul.nav_sec li').hoverIntent({
                sensitivity : 1, // number = sensitivity threshold (must be 1 or higher)
                interval : 200, // number = milliseconds for onMouseOver polling interval
                over : goDownNsa, // function = onMouseOver callback (REQUIRED)
                timeout : 300, // number = milliseconds delay before onMouseOut
                out : goUpNsa// function = onMouseOut callback (REQUIRED)
            });
        
        function check_mobile_device() {
            var user_agent_strings = {
                iphone : ['iphone', 'ipod'],
                android : ['android']
            }
            
            var user_agent = navigator.userAgent.toLowerCase();
            
            for (device in user_agent_strings) {
                for (ustring in user_agent_strings[device]) {
                    if (user_agent.search(user_agent_strings[device][ustring]) > -1)
                        return device;
                }
            }
            
            return false;
        }
        
        var mobile_browser = check_mobile_device();
        if (mobile_browser) {
            if (mobile_browser == 'android') {
                $("#background-Hidden").hide();
            }
        }
        
        // Ukljuci live feed ako postoji
        if($('.lf_slide').length > 0){            
            $('.lf_slide').verticalSlide ();
        }
    
    /* animiranje embed gumbica na flash playeru */
    $('#player2.embed_true, #embed_placeholder span').live('mouseover', function(){
        $('#embed_placeholder').show()
    });
    
    $('#player2, #player3').live('mouseout', function(){
        $('#embed_placeholder').hide()
    });
    
    $('#embed_placeholder span').live('click', function(){
        preuzmi_video($('#embed_placeholder span').text())
    });
    
    $('#fast_search input.text').keyup(function() {

        if($(this).val() == 'givemewaves'){        
        
            $('#nav_main ul.nav_sec').each(function(index){
                $(this).delay(index * 150).slideDown(300);
                // console.log(index)
            })
            
            $('#nav_main ul.nav_sec').each(function(index){
                $(this).delay(500).slideUp(300);
                // console.log(index)
            })
            
            $(this).blur();
            //$(this).unbind();
            
        }    
        
        if($(this).val() == 'ringeringeraja'){  
            
            var i = 0;
            function ringeraja(){
                 $('body').css({
                    '-moz-transform' : 'rotate(' + i + 'deg)',
                    '-webkit-transform' : 'rotate(' + i + 'deg)',
                    '-o-transform' : 'rotate(' + i + 'deg)',
                    '-ms-transform' : 'rotate(' + i + 'deg)'
                })
                i += 10;
                if(i == 370){
                    clearTimeout(t);
                }else{
                    t = setTimeout(ringeraja, 20);                    
                }
            }
            ringeraja();
            $(this).blur();
        }       
        
    });
    
    $('.make_it_a_link').each(function(index){
        var link = $(this);
        link.attr('style','cursor:pointer;');
        $(this).click(function(){
            window.location.href=link.attr('href')
        });
    });
   
     
   /* //Check if url hash value exists (for bookmark)
    $.history.init(pageload, { unescape: "/,&=" });  
         
    //Seearch for link with REL set to ajax
    $('#gallery_page .gallery a').click(function () {
         
        //grab the full url
        var hash = this.href.split('?').join("#!");
         
        //remove the # value
        hash = hash.replace(/^.*#!/, '');
        if(/^!/.test(hash)) {
            hash = hash.substring(1);
        }
         
        //for back button
        $.history.load('!'+ hash);  
         
        
        getPage();
     
        //cancel the anchor tag behaviour
        return false;
    });        */

    /*function pageload(hash) {
        //if hash value exists, run the ajax
        if (hash) getPage();   
    }
             
    function getPage() {
         
        //generate the parameter for the php script
        var data = document.location.hash.replace(/^.*#/, '');
    }*/
});    /* End document(ready) */



/* BillBoard Banner */
var b_Htmp;
function openBillboard(b_H) {
    
    var padBill = 10;
    
    if ($('.roll_banner_top span.open_close').length < 1) {
        $('.roll_banner_top').prepend('<span class="open_close">PRIKAÅ½I OGLAS</span>')
    }
    
    if (b_H == 0) {
        padBill = 0;
    }
    
    if (b_H != 0) {
        $('.roll_banner_top span.open_close').html('<a href="javascript:openBillboard(0)">ZATVORI OGLAS</a>');
        b_Htmp = b_H;
    } else {
        $('.roll_banner_top span.open_close').html('<a href="javascript:openBillboard(' + b_Htmp + ')">PRIKAÅ½I OGLAS</a>');
    }
    
    $('.roll_banner_top').animate({
            'height' : b_H + padBill
        }, 500);
    $('#leaderboard').css({
            'padding-bottom' : padBill,
            'padding-left' : 10
        }).animate({
            'height' : b_H
        }, 500);
}

function clearLeader() {
    
    var leaderholder = $('.banner_sec_top');
    leaderholder.removeAttr('style').removeClass('roll_banner_top');
    leaderholder.css({
            'padding-top' : '0',
            'overflow' : ''
        });
    
    var leaderboard = $('#leaderboard');
    leaderboard.removeAttr('style');
    leaderboard.css({
            'right' : 'auto',
            'overflow' : '',
            'position' : 'relative',
            'background-image' : 'none'
        });
}

/* Embedanje videa */
function preuzmi_video(videoUrl){  
    var width = 480;
    var height = 320;
    //var videoUrl ='http://hwcdn.net/r8g2h8a5/cds/24/2011/04/1842.flv';
    var videoConf = escape(escape("{'clip':{'url':'" + videoUrl + "'}}"));
    var articleUrl =  location.href;
    var URL = ('/widgets/video_code?video_conf='+ videoConf + '&article_url=' +articleUrl )
    do_popup({url: URL})
}